using System;
using System.ComponentModel;
using System.ComponentModel.Design;

using System.Drawing;
using System.Drawing.Drawing2D;

namespace Camalon.Drawing
{
	[Serializable]
	[ToolboxItem( true)]
	[ToolboxBitmap( typeof( ShapePen ), "Components.Shade.bmp")]
//	[ToolboxItemFilter("Camalon.Drawing.Shape", ToolboxItemFilterType.Require)]
    [Editor("Camalon.Drawing.Design.ShadeEditor, Camalon.Drawing.Design", typeof(System.Drawing.Design.UITypeEditor))]
    [Designer("Camalon.Drawing.Design.ShadeDesigner, Camalon.Drawing.Design", typeof(IDesigner))]
    public class Shade : ContainerComponentBase
	{

		Point				_offset;
		int					_repeat;
		ShapePen			_pen;
		ShapeFill			_fill;

//		public Shade(System.ComponentModel.IContainer container):this()
//		{
//			container.Add( this);
//		}

		public Shade():this( new Point(1,2), 1 ){}

		public Shade(Point offset):this( offset, 1 ){}

		public Shade(Point offset, int repeat)
		{
			_offset		= offset;
			_repeat		= repeat;
		}

		protected override void Dispose(bool disposing)
		{
			if( _fill != null) _fill.InternalChanged -= new EventHandler(OnInternalChanged);
			if( _pen != null) _pen.InternalChanged -= new EventHandler(OnInternalChanged);
			base.Dispose (disposing);
		}

		public override object Clone()
		{
			Shade shade =  base.Clone () as Shade;
			if( shade._fill != null) shade._fill.InternalChanged -= new EventHandler(OnInternalChanged);
			if( shade._pen != null) shade._pen.InternalChanged -= new EventHandler(OnInternalChanged);
			return shade;
		}


		[Category("Shade")]
		[DefaultValue(typeof(Point),"1,2")]
		[RefreshProperties( RefreshProperties.All)]
		public Point Offset
		{
			get{ return _offset;}
			set
			{ 
				if( _offset == value) return;
				_offset = value;

				InvokeInternalChanged();
			}
		}


		[DefaultValue(1)]
		[Category("Shade")]
		[RefreshProperties( RefreshProperties.All)]
		public int Repeat
		{
			get{ return _repeat;}
			set
			{ 
				if( _repeat == value) return;
				_repeat = value;

				InvokeInternalChanged();
			}
		}

		[DefaultValue(null)]
		[Category("Shade")]
		public ShapeFill Fill
		{
			get{ return _fill;}
			set
			{ 
				if( _fill != null) _fill.InternalChanged -= new EventHandler(OnInternalChanged);
				_fill = value;
				if( _fill != null) _fill.InternalChanged += new EventHandler(OnInternalChanged);
				InvokeInternalChanged();
			}
		}


		[DefaultValue(null)]
		[Category("Shade")]
		public ShapePen Pen
		{
			get{ return _pen;}
			set
			{ 
				if( _pen != null) _pen.InternalChanged -= new EventHandler(OnInternalChanged);
				_pen = value;
				if( _pen != null) _pen.InternalChanged += new EventHandler(OnInternalChanged);
				InvokeInternalChanged();
			}
		}

	}
}
